import { Controller, Post, Body } from '@nestjs/common'
import { MenuService } from './menu.service'

@Controller('menu')
export class MenuController {
  constructor(private readonly menuService: MenuService) { }

  // 获取角色菜单或者所有菜单
  @Post('getMenu')
  getMenu(@Body() body) {
    return this.menuService.getMenu(body.roleCode, body.isAllMenu)
  }

  // 新增菜单
  @Post('add')
  add(@Body() body) {
    // 示例
    // const data = {
    //   funcName: '资产管理',
    //   funcPerms: 'AssetManagement',
    //   url: '/asset-management',
    //   funcType: 1,
    //   parentId: 0,
    //   sortOrder: 0,
    //   funcIcon: 'i-system',
    //   compName: 'AssetManagement',
    //   compPath: '/asset-management',
    //   routeQuery: null,
    //   isCache: false,
    //   isDisplay: true,
    // };
    const data = {
      funcName: body.funcName || null,
      // funcPerms: body.funcPerms || null,
      url: body.url || null,
      funcType: body.funcType || null,
      parentId: body.parentId !== undefined ? body.parentId : null,
      sortOrder: body.sortOrder !== undefined ? body.sortOrder : null,
      funcIcon: body.funcIcon || null,
      compName: body.compName || null,
      compPath: body.compPath || null,
      routeQuery: body.routeQuery || null,
      isCache: body.isCache !== undefined ? body.isCache : false,
      isDisplay: body.isDisplay !== undefined ? body.isDisplay : false,
      remark: body.remark || null,
    }
    return this.menuService.add(data)
  }

  @Post('update')
  update(@Body() body) {
    return this.menuService.update(body)
  }

  // 菜单列表查询
  @Post('page')
  getPageList(@Body() body) {
    return this.menuService.getPageList()
  }

  // 删除菜单
  @Post('del')
  del(@Body() body) {
    return this.menuService.del(body.id)
  }
}
